﻿#include "ssBOBind.h"

namespace StarSeeker
{

bool ssVBOBind::Create(const void* pData, u32 size, u32 usage)
{
	if (!m_vbo.IsValid() && m_vbo.Create(usage))
	{
		m_vbo.Use();
		m_vbo.InitData(pData, size);
		m_vbo.Nonuse();
		return true;
	}
	return false;
}
bool ssVBOBind::CreateFloat(const ssfloat* pData, u32 count, u32 usage)
{
	if (!m_vbo.IsValid() && m_vbo.Create(usage))
	{
		m_vbo.Use();
		m_vbo.InitData(pData, count*cg_folat_size);
		m_vbo.Nonuse();
		return true;
	}
	return false;
}

ssIBOBind::ssIBOBind()
{
	m_indexCount = 0;
	m_bitType = 0;
}
bool ssIBOBind::Create8(const u8* pData, u32 count)
{
	if (!m_ibo.IsValid() && m_ibo.Create())
	{
		m_ibo.Use();
		m_ibo.InitData(pData, count*cg_u8_size);
		ssIBO::Nonuse();
		m_indexCount = count;
		m_bitType = SS_INDEX_8;
		return true;
	}
	return false;
}
bool ssIBOBind::Create16(const u16* pData, u32 count)
{
	if (!m_ibo.IsValid() && m_ibo.Create())
	{
		m_ibo.Use();
		m_ibo.InitData(pData, count*cg_u16_size);
		ssIBO::Nonuse();
		m_indexCount = count;
		m_bitType = SS_INDEX_16;
		return true;
	}
	return false;
}
bool ssIBOBind::Create32(const u32* pData, u32 count)
{
	if (!m_ibo.IsValid() && m_ibo.Create())
	{
		m_ibo.Use();
		m_ibo.InitData(pData, count*cg_u32_size);
		ssIBO::Nonuse();
		m_indexCount = count;
		m_bitType = SS_INDEX_32;
		return true;
	}
	return false;
}
bool ssIBOBind::Create(u32 bitType, const void* pData, u32 count)
{
	if (bitType == SS_INDEX_8)
	{
		return Create8((u8*)pData, count);
	}
	else if (bitType == SS_INDEX_16)
	{
		return Create16((u16*)pData, count);
	}
	else if (bitType == SS_INDEX_32)
	{
		return Create32((u32*)pData, count);
	}
	return false;
}

#ifndef SS_USE_GLES2
bool ssPBOBind::Create(const void* pData, u32 size, u32 usage /*= SS_VBO_STATIC*/)
{
	if (!m_pbo.IsValid() && m_pbo.Create(usage))
	{
		m_pbo.Use();
		m_pbo.InitData(pData, size);
		m_pbo.Nonuse();
		return true;
	}
	return false;
}
#endif

}
